class Course < ActiveRecord::Base
  belongs_to :creator, :class_name => "User", :foreign_key => "user_id"
  has_and_belongs_to_many :users
  has_many :events, :conditions => "type IS NULL OR type = ''", :dependent => :destroy, :order => "due_date DESC"
  has_many :assignments, :dependent => :destroy

  validates_presence_of :creator, :message => 'No puede no ser creado por nadie.'
  validates_presence_of :name, :message => 'Debes asignarle un nombre al curso.'
  validates_presence_of :description, :message => 'Debes describir el curso.'
  validates_uniqueness_of :name, :message => 'El nombre del curso debe ser único.'
end
